package com.catsic.mod.specification;

import org.apache.commons.lang.StringUtils;
import org.springframework.util.CollectionUtils;

import com.catsic.base.specification.BaseSpec;
import com.catsic.base.specification.QueryWraper;
import com.catsic.mod.condition.ReceiveMessageCondition;
import com.catsic.mod.entity.ReceiveMessage;

public class ReceiveMessageSpec extends BaseSpec<ReceiveMessage>{

	public ReceiveMessageSpec(ReceiveMessageCondition condition) {
		super(condition);
	}

	@Override
	protected void addCondition(QueryWraper<ReceiveMessage> queryWraper) {
		ReceiveMessageCondition condition=(ReceiveMessageCondition) getCondition();
		if(StringUtils.isNotBlank(condition.getUserName())){
			addEqualCondition(queryWraper, queryWraper.getRoot().get("user").get("username"),condition.getUserName());
		}
		if(!CollectionUtils.isEmpty(condition.getAddresseeName())){
			addInCondition(queryWraper, "addresseeName",condition.getAddresseeName());
		}
		if(StringUtils.isNotBlank(condition.getRemind())){		
		  addEqualCondition(queryWraper, "remind");
		}
	}

}
